import java.util.Scanner;

public class Test {
    //写一个函数返回参数二进制中1的个数
    public static void main(String[] args) {
        int n = 15;
        int count = 0;
        while (n != 0){
            n = n & (n-1);
            count++;
        }
        System.out.println("n的二进制中1的个数为" + count);
    }
    /*  15:
        1111
        15 & 14:
        1111 & 1110 -----> 1110
        14 & 13:
        1110 & 1101 -----> 1100
        12 & 11:
        1100 & 1011 -----> 1000
        8 & 7:
        1000 & 0111 -----> 0000 */



    public static void main2(String[] args) {
        for (int i = 0; i < 999999; i++) {

            //i = 123
            int count = 0;//记录位数
            int tmp = i;
            while (tmp != 0) {
                tmp /= 10;
                count++;
            }
            tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }

            if (sum == i) {
                System.out.println(i + "是自幂数");
            }

        }
    }
}
